<!--
 * @Author: xiaotiwen
 * @Date: 2020-05-15 14:22:36
 * @LastEditTime: 2020-07-07 18:57:37
 * @LastEditors: xiaotiwen
 * @FilePath: \eduweb\src\views\practiceManagement\dispersionPracticeApply\dispersionPracticeAudit.vue
 * @Description: 分散实习申请审核/详情
 -->
<template>
    <div class="disAudit">
        <div class="disAudit_first">
            <h2 class="disAudit_title">{{$t('dispersionPracticeApply.title.pageTitle')}}</h2>
            <wordTable :data="data" :label="label" />
        </div>
        <div class="disAudit_second" v-if="type!=='details'">
            <h2 class="disAudit_title">{{$t('message.check')}}</h2>
            <el-form ref="form" :model="form" label-position="right" label-width="90px">
                <el-form-item :label="$t('practiceManagement.opinion')">
                    <el-input v-model="form.content" maxlength="200" :rows="4" type="textarea" resize="none" />
                </el-form-item>
            </el-form>
            <div class="disAudit_second_bottom" v-if="pathKey!='details'">
                <el-button type="primary" class="disAudit_second_btn" @click="pass" :disabled="fromCheckDetail">{{$t('message.pass')}}</el-button>
                <el-button type="danger" @click="rejects" :disabled="fromCheckDetail">{{$t('message.reject')}}</el-button>
                <el-button @click="cancel">{{$t('message.cancel')}}</el-button>
            </div>
        </div>
        <div class="disAudit_third" v-if="data.status !== 'DRAFT'">
            <el-collapse accordion>
                <el-collapse-item>
                    <template slot="title">{{$t('achievementApply.approvals')}}</template>
                    <el-table :data="data1">
                        <el-table-column align="center" width="55" type="index" :label="$t('message.order')" />
                        <el-table-column v-for="(item, idx) in label1" :min-width="item.width" :key="idx" :label="item.label" :prop="item.props" align="center" />
                        <el-table-column prop="result" width="100" :label="$t('message.operating')">
                            <template slot-scope="scope">
                                <el-tag :type="fieldChange(auditStatus, scope.row.result, ['types', 'value'])"> {{ fieldChange(auditStatus, scope.row.result) }}</el-tag>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-collapse-item>
            </el-collapse>
        </div>
    </div>
</template>

<script>
import wordTable from '../common/wordTable';
import { getDetail } from 'common/src/api/practiceManagement/dispersionPracticeApply';
import commonMixins from '../commonMixins';
import { approvalThrough, approvalReject, approvelDetail } from 'common/src/api/approval';
export default {
    // 组件名称
    name: 'DispersionPracticeAudit',
    // 局部注册的组件
    components: {
        wordTable
    },
    mixins: [commonMixins],
    // 组件参数 接收来自父组件的数据
    props: {
        ids: {
            type: String,
            default: ''
        },
        type: {
            type: String,
            default: ''
        },
      dataInfo: {
        type: Object,
        default: {}
      },
      fromCheckDetail:{
        type: Boolean,
        required: false
      },
      pathKey: {
          type: String,
          default: ''
      },

    },
    // 组件状态值
    data() {
        return {
            form: {
                content: ''
            },
            data: {}, // 数据类型
            label: [
                [{ label: this.$t('fundingManagement.label.courseProgramNumber'), props: 'subCourseNo'},{ label: this.$t('fundingManagement.label.courseName'), props: 'courseName'}],
                [{ label: this.$t('label.stuCode'), props: 'studentNo' }, { label: this.$t('label.stuName'), props: 'studentName' }],
                [{ label: this.$t('label.college'), props: 'acdemyName' }, { label: this.$t('label.major'), props: 'majorName' }],
                [{ label: this.$t('label.grade'), props: 'grade' }, { label: this.$t('dispersionPracticeApply.label.practiceDateStart'), props: 'practiceDateStart' }],
                [{ label: this.$t('dispersionPracticeApply.label.practiceDateEnd'), props: 'practiceDateEnd' }, { label: this.$t('dispersionPracticeApply.label.practiceAddr'), props: 'practiceAddr' }],
                [{ label: this.$t('dispersionPracticeApply.label.practiceEnterprise'), props: 'practiceEnterprise' }, { label: this.$t('dispersionPracticeApply.label.enterpriseContactUser'), props: 'enterpriseContactUser' }],
                [{ label: this.$t('dispersionPracticeApply.label.position'), props: 'position' }, { label: this.$t('dispersionPracticeApply.label.enterpriseContactPhone'), props: 'enterpriseContactPhone' }],
                [{ label: this.$t('dispersionPracticeApply.label.practicePlan'), props: 'practicePlan' }],
                [{ label: this.$t('dispersionPracticeApply.label.attachName'), props: 'attachName', type: 'file' }]
            ],
            data1: [],
            label1: [
                { label: this.$t('paperBlindTrial.tiemName'), props: 'times', width: 200 },
                { label: this.$t('achievementApply.approvorName'), props: 'approvorName', width: 100 },
                { label: this.$t('academicApply.role'), props: 'role', width: 80 },
                { label: this.$t('achievementApply.explanation'), props: 'content', width: 250 }
            ],
            rules: {}
        };
    },
    // 计算属性
    computed: {},
    // 侦听器
    watch: {},
    /**
     * 在实例初始化之后，组件属性计算之前，如data属性等
     */
    created() { },
    /**
     * 在挂载开始之前被调用：相关的 render 函数首次被调用。
     */
    mounted() {
        if(this.dataInfo&&this.dataInfo.no){
          this.form=this.dataInfo.content;
          this.data=this.dataInfo.content;
          this.data.workFlowId=this.dataInfo.no;
          this.data1 = this.dataInfo.listApproveHistory;
        }else{
          this.getDetails();
        }
    },
    // 组件方法
    methods: {
        // 通过
        pass() {
            this.$eduConfirm(this.$t('dispersionPracticeApply.tips.confirmPass'), this.$t('message.prompt')).then(() => {
                let params = {
                    content: this.form.content,
                    no: this.data.workFlowId,
                    approveAttachment: [],
                    oaNo: this.data.workFlowId,
                    remark: null,
                    callbackEachTime: true
                };
                approvalThrough(params).then(res => {
                    if (res && res.code !== 200) {
                        this.$message({ message: res.msg, type: 'warning' });
                        return;
                    }
                    this.$emit('cancle-emit', 'refresh');
                    this.$message({ message: this.$t('practiceManagement.tips.checkSuc'), type: 'success' });
                });
            });
        },
        // 驳回
        rejects() {
            if (!this.form.content) {
                this.$message.warning(this.$t('dispersionPracticeApply.tips.rejectContent'));
                return;
            }
            this.$confirm(this.$t('dispersionPracticeApply.tips.areYouSureReject'), this.$t('message.prompt'), {
                confirmButtonText: this.$t('message.confirm'),
                cancelButtonText: this.$t('message.cancel'),
                type: "warning"
            }).then(() => {
                let params = {
                    content: this.form.content,
                    no: this.data.workFlowId,
                    approveAttachment: [],
                    oaNo: this.data.workFlowId,
                    remark: null,
                    callbackEachTime: true
                };
                approvalReject(params).then(res => {
                    if (res && res.code !== 200) {
                        this.$message({ message: res.msg, type: 'warning' });
                        return;
                    }
                    this.$emit('cancle-emit', 'refresh');
                    this.$message({ message: this.$t('dispersionPracticeApply.tips.rejectSuc'), type: 'success' });
                });
            });
        },
        cancel() {
          if(this.dataInfo.wfType==136){
              this.$router.go(-1);
          }else{
            this.$emit('cancle-emit');
          }

        },
        getDetails() {
            getDetail({ id: this.ids }).then(res => {
                this.data = res.data;
                if (this.data.udgPtAttachTs && this.data.udgPtAttachTs.length > 0) {
                    this.$set(this.data, 'attachName', this.data.udgPtAttachTs[0].attachName);
                    this.$set(this.data, 'attachPath', this.data.udgPtAttachTs[0].attachPath);
                }
                if (this.data.status !== 'DRAFT') {
                    this.approvelDetails(res.data.workFlowId);
                }
            });
        },
        approvelDetails(id) {
            approvelDetail({ no: id }).then(res => {
                this.data1 = res.data.listApproveHistory;
                this.data1.forEach(item => {
                    this.$set(item, 'times', this.formatDate(new Date(item.time), 'yyyy-MM-dd hh:mm:ss'));
                })
            })
        }
    }
};
</script>
<style lang="scss" scoped>
.disAudit {
    &_first {
        padding: 20px;
        background-color: #fff;
    }
    &_second {
        margin-top: 20px;
        padding: 20px;
        background-color: #fff;
        &_bottom {
            padding: 10px 0;
            display: flex;
            flex-direction: row-reverse;
        }
        &_btn {
            margin-left: 10px;
        }
    }
    &_third {
        margin-top: 20px;
        padding: 20px;
        background-color: #fff;
    }
    &_title {
        color: #2b3b4e;
        font-weight: bold;
    }
}
</style>
